<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

		<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>系统设置</a>
						</li>
						<li class="active">主链列表</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							主链列表
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<th>id</th>
												<th>名称</th>
												<th>备注</th>
												<!-- <th>手续费单位</th> -->
												<!--<th>最低gas</th>
												<th>最高gas</th>-->
												<th>操作</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
								</div>
							</div>
						</div>
					</div>

				</section>
			</div>
		</div>
		<div class="modal fade parents in" id="passwordModal" style="z-index:1051;">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header"> 
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	                  							<span aria-hidden="true">×</span>								
						</button>
						<h4 class="modal-title">密码确认</h4> 
					</div>
					<div class="modal-body">
						<form class="form-horizontal">
							<input type="password" class="form-control" name="OPassword" placeholder="请输入操作密码">	
						</form>
					</div>
					<div class="modal-footer"> 
						<button type="button" class="btn btn-primary save" onclick="editSave()">确定</button> 
					</div>
				</div>
			</div>
		</div>
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>

		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		<script src="bower_components/moment/min/moment.min.js"></script>
		<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>

		<script src="dist/js/adminlte.min.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script src="js/getList.js"></script>
		<script type="text/javascript">
			var table = $('#example').DataTable({
				'ordering': false,
				'lengthChange': false,
				'searching': false,
				'info': true,
				"processing": true,
				"serverSide": true,
				'scrollX':true,
				"ajax": {
					"type": 'post',
					"url": url + "Back_MainChain",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"data": function(d) {
						//						var dataType ={
						//							platform:{type:'string',value:$("#platform").val()}
						//						}
						var Json = {} //renderData(dataType);
						Json.page_num = d.start / 10 + 1;
						var data = {};
						data.data = JSON.stringify(Json);
						return data;
					},
					"dataFilter": function(data) {
						var datajson = eval('(' + data + ')');
						if(datajson.status == 1000||datajson.status == 102) {
							ToLogin(datajson)
							return false;
						} else if(datajson.status != 1) {
							alert(datajson.error);
							return false;
						}
						var json = {};
						if(datajson.data == null) {
							json.recordsTotal = 0;
							json.recordsFiltered = 0;
							json.data = [];
							return JSON.stringify(json);
						} else {
							json.recordsTotal = datajson.data.total;
							json.recordsFiltered = datajson.data.total;
							json.data = datajson.data.data_list;
							return JSON.stringify(json);
						}
					}
				},
				"columns": [{
						data: 'id'
					},
					{
						data: 'name'
					},
					{
						data: 'remark'
					},
					// {
					// 	data:null,render:function(data){
					// 		return data.name;
					// 	} //'charge_coin_id'
					// },
//					{
//						data: 'min_gas_limit'
//					},
//					{
//						data: 'max_gas_limit'
//					},
					{
						data: null,
						render: function(data) {
							return "<input type='hidden' value='" + JSON.stringify(data) + "'><button type='button' class='btn btn-primary button-margin' onclick='editChain(this)'><i class='fa fa-pencil'></i>&nbsp;编辑</button><button type='button' class='btn btn-primary button-margin' onclick='checkDetails(" + data.id + ")'><i class='fa fa-search'></i>&nbsp;查看详情</button>"
						}
					}
				]
			})
		</script>
		
		
		<script type="text/javascript">
			function editChain(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				var editJson = {
					name: "editChain",
					title: "主链编辑",
					arg: {
						id: {
							type: "id",
							value: data.id
						},
						name: {
							name: "名称",
							type: "text",
							value: data.name
						},
						// gas_name: {
						// 	name: "低单位名称",
						// 	type: "text",
						// 	value: data.gas_name
						// },
						remark: {
							name: "备注",
							type: "text",
							value: data.remark
						},
					}, //参数
				};
				editModal(editJson, 'editNext');
			}

			function editNext() {
				$("#passwordModal").modal('show');
				$("#passwordModal input").val("");
			}

			function editSave() {
				var data = {
					id: $("#editChainModal [name=id]").val(),
					name: $("#editChainModal [name=name]").val(),
					remark: $("#editChainModal [name=remark]").val(),
//					cold_address: $("#editChainModal [name=cold_address]").val(),
//					hot_address: $("#editChainModal [name=hot_address]").val(),
//					hot_address_private_key: $("#editChainModal [name=hot_address_private_key]").val(),
//					charge_coin_id: $("#editChainModal [name=charge_coin_id]").val(),
					// gas_name: $("#editChainModal [name=gas_name]").val(),
					op_password: $("#passwordModal [name=OPassword]").val(),
				}
				$.ajax({
					type: "post",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"contentType": "application/x-www-form-urlencoded",
					url: url + "Back_ChainUpdate",
					data: {
						data: JSON.stringify(data)
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#passwordModal").modal("hide");
						$("#editChainModal").modal("hide");
						move("success", '修改成功');
						table.draw(false);
					}
				})
			}

			function checkDetails(id) {
				window.location.href = 'chainDetails.html?chain_id=' + id;
			}
		</script>
	</body>

</html>